package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.controller.CarQRCodePrintController;
import com.tianqu.tms.www.car.viewhelper.CarQRCodePrintViewHelper;

public class CarQRCodePrintAction extends TmsAction{

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {
		//
		String serial = request.getParameter("serial");
		uc.setAttribute("serial",serial );
		CarQRCodePrintController controller = new CarQRCodePrintController();
		controller.execute(uc);
		//
		CarQRCodePrintViewHelper view = new CarQRCodePrintViewHelper();
		String brandName = (String)uc.getAttribute("brandName");
		if(StringUtil.isNotBlank(brandName)){
			if(brandName.length() <= 15){
				view.setBrandName((String)uc.getAttribute("brandName"));
			}else{
				String firstBrandName = brandName.substring(0, 15);
				String lastBrandName = brandName.substring(15);		
				view.setFirstBrandName(firstBrandName);
				view.setLastBrandName(lastBrandName);
			}
		}
		
		String vin = (String)uc.getAttribute("vin");
		if(StringUtil.isNotBlank(vin) && vin.length() > 8){
			int length = vin.length() - 8;
			view.setVin(vin.substring(length));
		}else{
			view.setVin(vin);
		}
		view.setSerial(serial);
		view.setUserMaket(TmsConstants.MARKET_NO);
		request.setAttribute(TmsConstants.VIEWHELP,view);
		return mapping.findForward(TmsConstants.SUCCESS);
	}
}
